<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>另存为模板</title>
    <jsp:include page="../../../head.jsp"/>
</head>
<script type="text/javascript">
    var formSetting = {
        action: '<s:url value="/business/saveModel"/>',
        module: 'save',
        columns: [{
            index: "MODEL_NAME",
            name: "model_name",
            label: "模板名称",
            validate: 'validate[required,funCall[ajaxCheckModelName]]'
        }, {
            index: "TYPE",
            name: "type",
            hidden: true,
            label: "模板类型",
//            type: "dropdown",
            value: "D",
            data: [["报关", "D"]],//, ["拖车", "C"]],
            validate: 'validate[required]'
        }],
        form: {
            url: '',
            method: 'post',
            ajaxForm: {
                /**
                 * 这里因为不需要使用控件本身的AJAX提交，所以使用error方法来存放自己的函数代码
                 * @param status
                 * @param errorStr
                 * @param syntaxError
                 */
                error: function (status, errorStr, syntaxError) {
                    var modelName = $("input[name='model_name']").val();
                    var type = $("input[name='type']").val();
                    var isRecordInfo = '${isRecordInfo}';
                    var businessId = '${businessId}';
                    parent.saveAsModel(modelName, type, isRecordInfo, businessId);
                }
            }

        }
    };
    $(document).ready(function () {
        $("#declarationModelForm").mrdForm(formSetting);
    });

    function ajaxCheckModelName() {
        var modelName = $("input[name='model_name']").val();
        var rs;
        $.ajax({
                   url: "<s:url value="/business/modelNameValidator"/>",
                   data: {
                       modelName: modelName
                   },
                   method: 'post',
                   dataType: 'json',
                   success: function (result) {
                       rs = result.rs;
                   }
               });
        if (rs === "0") {
            return "名称已经被占用";
        }
    }
</script>
<body>
<div id="declarationModelForm"></div>
</body>
</html>
